Error: Invalid Sample Rate
# support
h
I am using Vapi's python sdk and installed Ubuntu 24.04 LTS Desktop (Dual boot option with windows). I shifted to new os since Vapi does not support Windows. I even tried using wsl2 in windows but it does not have access to hardware like microphone. So I shifted to Ubuntu in hope that it would run. However, after successful installation, I am still getting invalid sample rate error. Complete log is attached in text file. https://cdn.discordapp.com/attachments/1265986700107055124/1265986700195266650/message.txt?ex=66a3817e&is=66a22ffe&hm=5ebcc1570e4410a68ec1ad75453e843d34c04d36530fbfb19b22a17368823c43&
v
@Hasan I'm glad to hear that you're using VAPI's Python SDK and have taken steps to ensure compatibility by switching to Ubuntu. The invalid sample rate error you're encountering is typically related to the audio configuration or the settings within the SDK or the application you're developing. To assist you better, I would need to take a look at the specific error message from the log file you've mentioned. Since you're unable to attach the file here, could you please provide me with the exact error message or describe the part of the log where the invalid sample rate error is mentioned? Once I have more details, I'll do my best to guide you through the troubleshooting process to resolve this issue.
You can continue this conversation by mentioning me in the message.
h
Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/home/hasan/Documents/NeuroOceansAI/leads_assistant/src/call/vapi_call.py", line 4, in vapi.start(assistant_id=VAPI_ASSISTANT_ID) File "/home/hasan/anaconda3/envs/vapi_crm/lib/python3.11/site-packages/vapi_python/vapi_python.py", line 45, in start self.__client = DailyCall() ^^^^^^^^^^^ File "/home/hasan/anaconda3/envs/vapi_crm/lib/python3.11/site-packages/vapi_python/daily_call.py", line 24, in __init__ self.__input_audio_stream = self.__audio_interface.open( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/hasan/anaconda3/envs/vapi_crm/lib/python3.11/site-packages/pyaudio/__init__.py", line 639, in open stream = PyAudio.Stream(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/hasan/anaconda3/envs/vapi_crm/lib/python3.11/site-packages/pyaudio/__init__.py", line 441, in __init__ self._stream = pa.open(**arguments) ^^^^^^^^^^^^^^^^^^^^ OSError: [Errno -9997] Invalid sample rate
v
@Hasan Thank you for providing the traceback. The error
[Errno -9997] Invalid sample rate
indicates that PyAudio, the library used for handling audio streams in Python, is unable to open an audio stream with the specified sample rate because it's not supported by your audio hardware or the configuration is incorrect. Here are a few steps you can take to troubleshoot this issue: 1. **Check Audio Hardware Support**: Ensure your audio hardware supports the sample rate you're trying to use. You can use the command
arecord --list-devices
and
arecord --list-pcms
to list supported devices and formats. 2. **PyAudio Stream Parameters**: Check the parameters you're passing to PyAudio when opening the stream. Make sure the
rate
parameter matches one of the supported sample rates of your audio hardware. 3. **Update PyAudio**: If you're not using the latest version of PyAudio, consider updating it as there might be fixes related to audio handling. 4. **Audio Drivers**: Ensure that your audio drivers are up to date and properly configured. 5. **Alternative Sample Rates**: Try using a common sample rate like 44100 or 48000 Hz, which are widely supported by most audio hardware. 6. **Virtual Environment**: Since you're using Anaconda, ensure that the virtual environment is properly set up and that there are no conflicts with the system-wide Python installation. 7. **Permissions**: Make sure you have the necessary permissions to access the audio hardware on Ubuntu. If after trying these steps the issue persists, it might be helpful to consult the documentation for VAPI's Python SDK or reach out to their support team for assistance specific to their software. Remember to test your changes incrementally, and if you make any progress or encounter different errors, feel free to share them here for further assistance.
@Hasan Based on the information you've provided, it looks like you have two audio capture devices available on your system. To resolve the invalid sample rate error, you can try specifying the correct audio device and sample rate when initializing PyAudio. Here's what you can do: 1. **Specify the Correct Audio Device**: Use the
hw:CARD=Generic_1,DEV=0
or
hw:CARD=acp,DEV=0
device, depending on which one you want to use for capturing audio. 2. **Determine Supported Sample Rates**: You can use the
arecord
command with the
--dump-hw-params
flag to find out the supported sample rates for a specific device. For example:
Copy code
arecord --device=hw:CARD=Generic_1,DEV=0 --dump-hw-params
Look for the
RATE
values to see the supported sample rates. 3. **Configure PyAudio**: When initializing PyAudio, make sure to set the
input_device_index
to the index of the device you want to use and the
rate
to one of the supported sample rates. For example:
Copy code
python
   import pyaudio

   p = pyaudio.PyAudio()
   stream = p.open(format=pyaudio.paInt16,
                   channels=1,
                   rate=44100,  # or another supported rate
                   input=True,
                   input_device_index=1,  # or the index of 'acp' if you prefer
                   frames_per_buffer=1024)
4. **Test the Configuration**: After setting the correct device and sample rate, run your application again to see if the issue is resolved. If you're still encountering issues, you may need to adjust the configuration further or consult the VAPI Python SDK documentation for any additional settings or requirements specific to the SDK. Remember to replace the
input_device_index
and
rate
with the correct values for your setup. If you're unsure about the index, you can iterate over the devices using PyAudio's
get_device_info_by_index()
method to print out the names and indices of the devices.
h
@User @User Please guide
s
mostly related to your pyaudio setup.
can you please share the code snippet.
h
from vapi_python import Vapi from src.utils.utils import VAPI_API_KEY, VAPI_ASSISTANT_ID vapi = Vapi(api_key=VAPI_API_KEY) vapi.start(assistant_id=VAPI_ASSISTANT_ID)
s
it's problem with pyaudio because of sample rate as visible
i will try to reproduce the same
h
Please let me know when done
s
i tried reproducing but couldn't it's working for me, looks like your device specific.
7 Views